package ObjectVC;

import java.util.ArrayList;
import java.util.Date;

import javax.swing.JOptionPane;

public aspect compare {
	after(Object actualObj, Action action, ArrayList<Object> actionParams): 
		VCOperations.VCops(actualObj, action, actionParams) 
		&& if(action.equals(Action.Compare)){
		if (null != actionParams && actionParams.size()>0){
			Object obj = actionParams.get(0);
			Integer idx = null;
			Date timestamp = null;
			
			if (null == obj){
				JOptionPane.showMessageDialog(null, "Object is null");
				return;
			}
			
			if (actionParams.size()==1)
				showCompare(obj, DB.getLatestVersion(obj));
			else if (actionParams.size()==2){
				if(actionParams.get(1).getClass().equals(Integer.class)){
					idx = (Integer) actionParams.get(1);
					showCompare(obj, DB.getVersion(obj, idx));
				}
				else if(actionParams.get(1).getClass().equals(Date.class)){
					timestamp = (Date) actionParams.get(1);
					showCompare(obj, DB.getVersion(obj, timestamp));
				}
			}
		}
	}

	private void showCompare(Object obj, Version version) {
		// TODO Auto-generated method stub
		
	}
}
